package crudfx.util;

import javax.script.*;

/**
 * <p>JavaScript engine</p>
 * <p><b>Example</b>
 * <i>Execute script</i></p>
 * <pre>
package testbox;

import java.util.*;

var js:JS=JS{};
    js.evaluate("print('Hello, World\\n')");
    var t:Properties=new Properties();
    println(t.getProperty("a"));
    js.add(t, "test");
    js.evaluate("test.setProperty('a','b1');print(test.getProperty('a'))");
    println(t.getProperty("a"));
 </pre>
 * @profile desktop
 * @author Sergey Surikov
 */
public class JS {
    var engine:ScriptEngine;
    init{
	var factory:ScriptEngineManager=new ScriptEngineManager();
	engine=factory.getEngineByName("JavaScript");
    }
    public function evaluate(command:String):Void{
        engine.eval(command);
        }
    public function add(object:Object,name:String):Void{
        engine.put(name,object);
        }
    }
public function run(args:String[]):Void{
    var js:JS=JS{};
    js.evaluate("print(1+2)");
    /*var t:Properties=new Properties();
    println(t.getProperty("a"));
    js.add(t, "test");
    js.evaluate("test.setProperty('a','b1');print(test.getProperty('a'))");
    println(t.getProperty("a"));*/
}
